<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../common.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>监控项列表</title>
<style> 
.table-edit {
	border-collapse: collapse;
	border-spacing:0; 
}
.table-edit tr{height:22px;}
.table-edit td{	
	border-color:#cccccc;
	border-width:0px 0px 1px 0px;
	padding:5px;
	text-align: left;
}
</style>
<script>
$(function() { 
	$('#list').datagrid({
		url: '${ctx}/monitorItem/monitorItemList',
// 		queryParams:{"isLoad":1},
		height: size.height-120,
		idField: 'id',
		nowrap: false, //内容换行
		striped: true, //条纹
        fit: true,
		singleSelect: true, //是否单选
        frozenColumns: [[
        	{field:'ck',checkbox:true}
        ]],
		columns: [[
			{field:"id",title:"编号",align:"center",sortable:true,width:fixWidth(0.05)},  
			{field:"systemId",title:'所属系统',align:"center",width:fixWidth(0.1),
				formatter : function(value, rowData) {
					switch (value) {
					case 1:
						return "贷后";
						break;
					case 2:
						return "呼叫中心";
						break;
					default:
						break;
					}
				}
			},
			{field:"name",title:'监控项名称',width:fixWidth(0.2)},
			{field:"thresholdType",title:'阈值类型',align:"center",width:fixWidth(0.05),
				formatter : function(value, rowData) {
					switch (value) {
					case 1:
						return "<";
						break;
					case 2:
						return ">=";
						break;
					case 3:
						return "<=";
						break;
					default:
						return ">";
						break;
					}
				}
			},
			{field:"threshold",title:'阈值',align:"center",width:fixWidth(0.05)},
			{field:"executeMinute",title:'执行频率',align:"center",width:fixWidth(0.1)},
			{field:"alarm",title:'监控状态',align:"center",width:fixWidth(0.1),
				formatter : function(value, rowData) {
					if(value){
						return "<font color='red'>警报</font>";
					}else{
						return "<font color='green'>正常</font>"
					}
				}
			},
			{field:"_opt",title:'操作',align:"center",width:fixWidth(0.15),
				formatter : function(value, rowData) {
					var btn = '<a style="color:blue" href="#" onclick="againInspect('+rowData.id+')" >检查</a> &nbsp;&nbsp;'; 
					if(rowData.enable){
						btn += '<a style="color:red" href="#" onclick="enableMonitor('+rowData.id+', false)" >删除</a> &nbsp;&nbsp;'; 
					}else{
						btn += '<a style="color:green" href="#" onclick="enableMonitor('+rowData.id+', true)" >启用</a> &nbsp;&nbsp;'; 
					}
					btn += '<a style="color:blue" href="#" onclick="ccManage('+rowData.id+')" >抄送</a>'; 
					return btn;
				}
			},
			{field:"_view",title:'查看',align:"center",width:fixWidth(0.1),
				formatter : function(value, rowData) {
					var btn = '<a style="color:blue" href="#" onclick="viewAlarmData('+rowData.id+')" >查看</a> &nbsp;&nbsp;'; 
					return btn;
				}
			}	
		]],
		rownumbers : true, //记录号
		pagination : true,
        toolbar: "#tb"
	}); 
	//初始化分页
	initListPage("list");
});

//查询
function searchResult(){
	var id = $("#id").val();
	var name = $("#name").val();
	var systemId = $("input[name='systemId']").val();
	var sdata = {
		"id" : id,
		"name" : name,
		"systemId" : systemId
	};
	$('#list').datagrid('load', sdata);
	$('#list').datagrid("clearSelections");
}

//重置
function resetedResult(){
	$('#searchForm').form('load',{
		id:'',
		name:'',
		systemId:''
	});
}

//重新检查
function againInspect(id){
	$.ajax({
		url:'${ctx}/monitorItem/againInspect?id='+id,
		type: "POST",
		dataType:'json',
		success: function(opt){
			if(opt.success){
				reloadList();
			}
			alert(opt.message);
		}
	});
}

//查看报警数据
function viewAlarmData(id){
	//新开tab展示监控项报警数据
	parent.addTab("监控数据【"+id+"】","${ctx}/monitorItem/toAlarmDataList?itemId="+id,'');
}

</script>
</head>
<body class="easyui-layout">
<div data-options="region:'north',title:'搜索条件',split:true" style="height:100px;"  >
	<form action="" name="searchForm" id="searchForm" method="post"> 
		<table class="table-edit" style="margin:10px;">
			<tr>
				<td align="right">
					<span>监控项编号：</span>
				</td>
				<td align="left">
					<input class="easyui-textbox" id="id" name="id" style="width:180px;">
				</td>
				<td align="right">
					<span>监控项名称：</span>
				</td>
				<td align="left">
					<input class="easyui-textbox" id="name" name="name" style="width:180px;">
				</td>
<!-- 				<td align="right"> -->
<!-- 					<span>时间：</span> -->
<!-- 				</td> -->
<!-- 				<td align="left"> -->
<!-- 					<input type="text" class="easyui-datetimebox" name="createStartDate" id="createStartDate" />- -->
<!-- 					<input type="text" class="easyui-datetimebox" name="createEndDate" id="createEndDate" /> -->
<!-- 				</td> -->
				<td align="right">
					<span>所属系统：</span>
				</td>
				<td align="left">
					<select class="easyui-combobox" id="systemId" name="systemId" style="width:180px;">
						<option value="">请选择...</option>
						<c:forEach items="${systemList}" var="system" varStatus="status">
							<option value="${system.id}">${system.name}</option>
						</c:forEach>
					</select>
				</td>
				<td>
					<a href="javascript:void(0)" class="easyui-linkbutton" onclick="searchResult()" style="width:80px">搜索</a>
					<a href="javascript:void(0)" class="easyui-linkbutton" onclick="resetedResult()" style="width:80px">重置</a>
				</td>
			</tr>
		</table>
	</form>
</div>

<!-- 列表 -->
<div data-options="region:'center'" style="overflow: hidden;">
    <table id="list"></table>
</div> 

<!-- 按钮区 -->
<div id="tb">
	<span>
	    <a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addMonitorItem()">添加监控项</a>
	</span>
	<span>
	    <a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editMonitorItem()">编辑监控项</a>
	</span>
</div>

<!-- 弹窗 -->
<div id="addMonitorItemDiv">
	<iframe id="monitorItemIframe" width="100%" height="510" style="border:0" src="" ></iframe>
</div>

<!-- 弹窗 -->
<div id="ccManageDiv">
	<iframe id="ccManageIframe" width="100%" height="510" style="border:0" src="" ></iframe>
</div>

<script type="text/javascript">
//抄送管理
function ccManage(id){
	$("#ccManageDiv").dialog({
		title: "抄送管理【"+id+"】",
		modal: true,
		width: 850,
		height: 550		
	});
	$("#ccManageIframe").attr("src","${ctx}/monitorCc/toList?itemId="+id)
  	$('#ccManageDiv').dialog('open');
}

//添加监控项
function addMonitorItem(){
	$("#addMonitorItemDiv").dialog({
		title: "监控项",
		modal: true,
		width: 850,
		height: 550		
	});
	$("#monitorItemIframe").attr("src","${ctx}/monitorItem/toEdit")
  	$('#addMonitorItemDiv').dialog('open');
}

//编辑监控项
function editMonitorItem(){
	//获取选中项
	var row = $('#list').datagrid('getSelected');
	if (!row){
		$.messager.alert('提示', "请选择监控记录");
		return;
	}
	$("#addMonitorItemDiv").dialog({
		title: "监控项",
		modal: true,
		width: 700,
		height: 550		
	});
	$("#monitorItemIframe").attr("src","${ctx}/monitorItem/toEdit?id="+row.id);
  	$('#addMonitorItemDiv').dialog('open');
}

//启用禁用监控
function enableMonitor(id, enable){
    $.ajax({
		url: '${ctx}/monitorItem/enableMonitor',
		data: {
			'id': id,
			'enable': enable
		},
		type: "POST",
		dataType:'json',
		success: function(opt){
			$.messager.alert('操作提示', opt.message);
			reloadList();
		}
	});
}
</script>
</body>
</html>